﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Gencode.Common.Errorhandling
{
	public class Handler : Logger, IHandler
	{
		public void ShowError(string errorMessage)
		{
			Gencode.Common.Errorhandling.MessageBox.Show(errorMessage, "");
		}

		public void ShowError(string errorMessage, string caption)
		{
			Gencode.Common.Errorhandling.MessageBox.Show(errorMessage, caption);
		}

		public void LoggError(string errorMessage)
		{
			ToXML(errorMessage);
		}

		public void LoggError(string caption, string location, string errorText)
		{
			ToXML(caption, location, errorText);
		}

		/// <summary>
		/// Writes an error to the Windows Event Log.
		/// </summary>
		/// <param name="caption">Should be the name of the application</param>
		/// <param name="exception">Exception that occured</param>
		public void LoggError(string caption, Exception exception)
		{
			// Errorhandling
			System.Diagnostics.EventLog objEventLog = new System.Diagnostics.EventLog();
			objEventLog.Source = caption;
			objEventLog.WriteEntry(exception.Message.ToString());
		}
	}
}
